<?php
/**
 * $filename
 *
 * @version            $id
 * @createtime        2020/5/13
 * @updatetime        ${time}
 * @author          bluarry
 * @copyright        Copyright @ bluarry
 */

class Table_qqdata
{
    static public $table_name="ads";
    static public function add($qqnum, $groupnum, $kicktime,$ad){
        global $mypdo;
        //写入数据库
        $param = array (
            'qq'   => array('string', $qqnum),
            'qqgroup'  => array('string', $groupnum),
            'adtime'      => array('string', $kicktime),
            'ads'     => array('string', $ad),
            'optime'   => array('string', date('Y-m-d H:i:s'))
        );
        return $mypdo->sqlinsert(Table_qqdata::$table_name, $param);
    }
    static public function alldata($page_index,$page_size){
        global $mypdo;
        $TABLE_NAME=Table_qqdata::$table_name;
        $offs=($page_index-1)*$page_size;
        $sql="SELECT * FROM $TABLE_NAME ORDER BY id DESC LIMIT $page_size OFFSET $offs;";
        return $mypdo->sqlQuery($sql);
    }
    static public function delte($id){
        $param = array (
            'id'   => array('int', $id)
        );
        $TABLE_NAME=Table_qqdata::$table_name;
        global $mypdo;
        return $mypdo->sqldelete($TABLE_NAME,$param);
    }

    static function filtdata($page_index,$page_size,$param){
        global $mypdo;
        $TABLE_NAME=Table_qqdata::$table_name;
        $cond=" WHERE ";
        if($param['qq']!=''){
            $p=$param['qq'];
            $cond=$cond." (qq=$p) AND ";
        }
        if($param['groupnum']!=''){
            $p=$param['groupnum'];
            $cond=$cond." (qqgroup=$p) AND ";
        }
        if($param['start']!=''&& $param['end']!=''){
            $st=$param['start'];
            $ed=$param['end'];
            $cond=$cond." (strftime('%s',adtime)>=strftime('%s','$st') AND strftime('%s',adtime)<= strftime('%s','$ed')  ) AND";
        }
        $cond=$cond.' 1=1 ';

        $offs=($page_index-1)*$page_size;
        $sql="SELECT * FROM $TABLE_NAME $cond ORDER BY id DESC LIMIT $page_size OFFSET $offs;";
        //echo $sql;
        return $mypdo->sqlQuery($sql);
    }

}